﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PanhuaWin
{
    public partial class Form发货记录查询 : UIPage
    {
        public Form发货记录查询()
        {
            InitializeComponent();
        }

        private void uiButton查询_Click(object sender, EventArgs e)
        {
            查询发货记录();
        }

        private void 查询发货记录()
        {
            decimal 总重 = 0;
            string sql = @"select Bus_DeliveryV.DocCode 发货单号,Bus_DeliveryVolume.WarehouseCode 仓库编号,
                         Bus_DeliveryVolume.WarehouseName 仓库名,Bus_DeliveryVolume.VolumeNumber 卷号,Bus_DeliveryVolume.Weight 重量
                        ,Bus_DeliveryVolume.Chepai 车牌,Bus_DeliveryVolume.status 发货状态,Bus_DeliveryVolume.ModifyDate 扫码日期,
                        Bus_DeliveryVolume.Modifier 扫码人,Bus_DeliveryVolume.船号
                        from Bus_DeliveryV
                        left join Bus_DeliveryVolume 
                        on Bus_DeliveryV.guid = Bus_DeliveryVolume.guid
                        where 1=1";
            if (!string.IsNullOrWhiteSpace(uiTextBox单号.Text.Trim()))
            {
                sql += " and Bus_DeliveryV.DocCode like '%"+ uiTextBox单号.Text.Trim()+ "%'";
            }
            if (!string.IsNullOrWhiteSpace(uiTextBox卷号.Text.Trim()))
            {
                sql += " and Bus_DeliveryVolume.VolumeNumber like '%" + uiTextBox卷号.Text.Trim() + "%'";
            }
            if (!string.IsNullOrWhiteSpace(uiTextBox仓库.Text.Trim()))
            {
                sql += " and Bus_DeliveryVolume.WarehouseName like '%" + uiTextBox仓库.Text.Trim() + "%'";
            }
            sql += " and ((Bus_DeliveryVolume.ModifyDate >= '"+uiDatePicker开始日期.Value + "'";
            sql += " and Bus_DeliveryVolume.ModifyDate <= '"+ uiDatePicker结束日期.Value.AddDays(1) + "')";

            sql += " or( Bus_DeliveryVolume.HandleTime >= '" + uiDatePicker开始日期.Value + "'";
            sql += " and Bus_DeliveryVolume.HandleTime <= '" + uiDatePicker结束日期.Value.AddDays(1) + "'))";

            DataTable dt = pub.GetDataTable(pub.ConnectionString,sql);
            if (dt != null && dt.Rows.Count > 0) 
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string 重量 = dt.Rows[i]["重量"].ToString();
                    decimal.TryParse(重量,out decimal 重);
                    总重 += 重;
                }
                uiTextBox总卷数.Text = dt.Rows.Count+"";
                uiTextBox总重.Text = 总重.ToString();
            }
            uiDataGridView1.DataSource = dt;
            uiDataGridView1.Refresh();
        }

        private void Form发货记录查询_Load(object sender, EventArgs e)
        {
            uiDatePicker开始日期.Value = DateTime.Now.AddDays(-1);
            uiDatePicker结束日期.Value = DateTime.Now;
        }
    }
}
